package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@Tag(name = "商品分类管理模块")
@RequestMapping("/admin/product/category")
public class CategoryController {
    @Resource
    CategoryService categoryService;
    @Operation(summary = "根据父id查询分类列表")
    @GetMapping("listByParentId/{pid}")
    public Result<List<Category>> listByParentId(@PathVariable("pid") Long pid){
        List<Category> categories = categoryService.listByParentId(pid);
        return Result.ok(categories);
    }
    //导出分类数据到excel文件中给前端
    @Operation(summary = "导出分类数据的excel文件")
    @GetMapping("export")
    public void exportCates(HttpServletResponse response){ //返回void表示 不通过springmvc设置响应体
        categoryService.exportCates(response);
    }

    @Operation(summary = "导入分类数据的excel文件")
    @PostMapping("import")
    public Result importCates(MultipartFile excel){
        categoryService.importCates(excel);
        return Result.ok(null);
    }
}
